package com.wedo.mall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.e.library.adapter.Adapter;
import com.wedo.mall.R;
import com.wedo.mall.db.DBHelper;
import com.wedo.mall.entity.Account;
import com.wedo.mall.util.WUrl;

import java.util.List;

/**
 * Created by e on 2017/10/30.
 */

public class AccountAdapter extends Adapter<Account> {

    public AccountAdapter(Context context, List<Account> datas) {
        super(context, datas);
    }

    @Override
    protected int layout() {
        return R.layout.item_account;
    }

    @Override
    protected void bind(EHolder holder, final Account account, final int position) {

        TextView tv_account = holder.find(R.id.tv_account);
        tv_account.setText(account.username);
        ImageView iv_img = holder.find(R.id.iv_img);
        ImageView iv_delete = holder.find(R.id.iv_delete);

        String img = WUrl.url(account.headimgurl);
        Glide.with(mContext).load(img).error(R.drawable.ic_avatar).placeholder(R.drawable.ic_avatar).diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_img);

        iv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DBHelper.with(mContext).delete(account.id);
                remove(position);
            }
        });

    }
}
